{% extends 'todo/base.html' %}

{% block content %}
<div class="template-manager">
    <h2>管理任务模板</h2>

    <div class="form-container">
        <h3>创建新模板</h3>
        <form method="post">
            {% csrf_token %}
            {{ form.as_p }}
            <button type="submit">保存模板</button>
        </form>
    </div>

    <hr>

    <div class="template-list">
        <h3>已有模板</h3>
        {% for template in templates %}
            <div class="template-item">
                <h4>{{ template.title }}</h4>
                <p><strong>重复频率:</strong> {{ template.get_repeat_frequency_display }}</p>
                <p><strong>优先级:</strong> {{ template.get_priority_display }}</p>
                {% if template.category %}
                    <p><strong>分类:</strong> <span class="category-tag">{{ template.category.name }}</span></p>
                {% endif %}
                <form action="{% url 'delete_template' template.id %}" method="post" style="display: inline;">
                    {% csrf_token %}
                    <button type="submit" onclick="return confirm('确定删除这个模板吗？')" class="delete-btn">删除</button>
                </form>
            </div>
        {% empty %}
            <p>还没有任何任务模板。</p>
        {% endfor %}
    </div>
</div>

<style>
    .template-manager {
        padding: 20px;
    }
    .form-container, .template-list {
        margin-bottom: 30px;
    }
    .template-item {
        border: 1px solid #ddd;
        padding: 15px;
        margin-bottom: 15px;
        border-radius: 5px;
        background-color: #f9f9f9;
    }
    .delete-btn {
        background-color: #dc3545;
        color: white;
    }
</style>
{% endblock %} 